package puzzle.puzzleup2008;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Footballers {

	/**
	 * @param args
	 */
	@SuppressWarnings("unchecked")
	public static void main(String[] args) {

		List<List<Integer>> as = null;
		//kind 1
		as = get(33, new Integer[] {1,2,3,4,5,6,7,8,9,10,11});
		int n1 = 0;
		for (int i = 0; i < as.size(); i ++) {
			for (int j = i+1; j < as.size(); j ++) {
					if (merge(as.get(i),as.get(j)).size() == 11) {
						System.out.println(as.get(i) + "-" + as.get(j));
						n1 ++;
					}
			}
		}
		//kind 2
		int n2 = 0;
		as = get(22, new Integer[] {1,2,3,4,5,6,7,8,9,10,11});
		for (int i = 0; i < as.size(); i ++) {
			for (int j = i+1; j < as.size(); j ++) {
				for (int k = j+1; k < as.size(); k ++) {
					if (merge(as.get(i),as.get(j),as.get(k)).size() == 11) {
						System.out.println(as.get(i) + "-" + as.get(j) + "-" + as.get(k));
						n2 ++;
					}
				}
			}
		}
		System.out.println(n1+n2);
	}
	
	public static Set<Integer> merge(List<Integer>... as) {
		Set<Integer> s = new HashSet<Integer>();
		for (List<Integer> a: as) {
			for (Integer n: a) {
				s.add(n);
			}
		}
		return s;
	}
	
	public static List<List<Integer>> get(int sum, Integer[] ns) {
//		System.out.println("Problem:" + sum + " " + Arrays.asList(ns));
		List<List<Integer>> answers = new ArrayList<List<Integer>>();
		Arrays.sort(ns);
		if (ns == null || ns.length == 0 || ns[0] > sum) {
//			System.out.println("WRONG");
		} else if (sum == ns[0]) {
			List<Integer> a = new ArrayList<Integer>();
			a.add(ns[0]);
			answers.add(a);
		} else {
			Integer[] newNs = new Integer[ns.length-1];
			System.arraycopy(ns,1,newNs,0,newNs.length);
			//kind 1:
			List<List<Integer>> newAnswers1 = get(sum-ns[0], newNs);
			for (List<Integer> a: newAnswers1) {
				a.add(ns[0]);
				answers.add(a);
			}
			//kind 2:
			List<List<Integer>> newAnswers2 = get(sum, newNs);
			for (List<Integer> a: newAnswers2) {
				answers.add(a);
			}
		}
		return answers;
	}

}
